package cn.bdqn.web;

import cn.bdqn.entity.Customer;
import cn.bdqn.service.CustomerServiceImpl;

import javax.servlet.annotation.WebServlet;
import java.io.IOException;
import java.util.List;

@WebServlet("/customer")
public class CustomerServlet extends javax.servlet.http.HttpServlet {
    protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {

    }

    protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
        // 调用 service 层 获取所有的 数据库数据
        CustomerServiceImpl customerService = new CustomerServiceImpl();
        List<Customer> customers = customerService.selectAll();
        // 添加到请求域 , 并转发
        request.setAttribute("customers",customers);
        request.getRequestDispatcher("/").forward(request,response);
    }
}
